﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using FineAdmin.Web.Controllers;
using FineAdmin.Web.Areas.SysSet.Models;
using FineAdmin.IService;

namespace FineAdmin.Web.Areas.SysSet.Controllers
{
    public class WebSetController : BaseController
    {
        //public ISystemParameterService SystemParameterService { get; set; }
        // GET: SysSet/WebSet
        public override ActionResult Index(int? id)
        {
            var sp = SystemParameterService.GetAll();
            var webModel = new WebModel();
            webModel.SiteName = sp.First(m=>m.Code== "SiteName").SPValue;
            webModel.SiteDomain = sp.First(m => m.Code == "SiteDomain").SPValue;
            webModel.Corporate = sp.First(m => m.Code == "CompanyName").SPValue;
            webModel.Address = sp.First(m => m.Code == "CompanyAddress").SPValue;
            webModel.Tel = sp.First(m => m.Code == "CompanyPlane").SPValue;
            webModel.Phone = sp.First(m => m.Code == "CompanyPhone").SPValue;
            webModel.Email = sp.First(m => m.Code == "CompanyEmail").SPValue;
            webModel.HomeTitle = sp.First(m => m.Code == "HomeTitle").SPValue;
            webModel.MetaKey = sp.First(m => m.Code == "METAKey").SPValue;
            webModel.MetaDescribe = sp.First(m => m.Code == "METADes").SPValue;
            webModel.Record = sp.First(m => m.Code == "ICP").SPValue;
            webModel.CopyRight = sp.First(m => m.Code == "COPYRIGHT").SPValue;
            webModel.SiteLogo = sp.First(m => m.Code == "SiteLogo").SPValue;

            //return View(new WebModel().GetWebInfo());

            return View(webModel);
        }
        [HttpPost]
        public ActionResult Index(WebModel model) 
        {
            try
            {
                new WebModel().SetWebInfo(model);
                SystemParameterService.UpDateVale("SiteName", model.SiteName);
                SystemParameterService.UpDateVale("SiteDomain", model.SiteDomain);
                SystemParameterService.UpDateVale("CompanyName", model.Corporate);
                SystemParameterService.UpDateVale("CompanyAddress", model.Address);
                SystemParameterService.UpDateVale("CompanyPlane", model.Tel);
                SystemParameterService.UpDateVale("CompanyPhone", model.Phone);
                SystemParameterService.UpDateVale("CompanyEmail", model.Email);
                SystemParameterService.UpDateVale("HomeTitle", model.HomeTitle);
                SystemParameterService.UpDateVale("METAKey", model.MetaKey);
                SystemParameterService.UpDateVale("METADes", model.MetaDescribe);
                SystemParameterService.UpDateVale("ICP", model.Record);
                SystemParameterService.UpDateVale("COPYRIGHT", model.CopyRight);
                SystemParameterService.UpDateVale("SiteLogo", model.SiteLogo);

            }
            catch (Exception ex)
            {
                ViewBag.Msg = "Error:"+ex.Message;
                return View(new WebModel().GetWebInfo());
            }
            ViewBag.Msg = "修改成功！";
            return View(new WebModel().GetWebInfo());
        }

        
    }
}